/*******************************************************************************
 * Copyright (c) 2005, 2014 springside.github.io
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *******************************************************************************/
package com.benmei.weike.rest;

import org.springframework.http.HttpStatus;

/**
 * 专用于Restful Service的异常.
 * 客户端错误抛出此异常信息
 */
public class RestClientException extends RuntimeException {

    private int status = HttpStatus.BAD_REQUEST.value();
    private Long timestamp = System.currentTimeMillis();
    private String message;// 给用户看到友好的消息，提示用户错误原因，或者碰到这个错误该如何操作
    private String errorDetail;// 给开发看的错误详情，用于定位错误原因。

    public String toJson(){
        return "{\"status\":"+status+", \"timestamp\":"+timestamp+", \"message\":\""+message+"\", \"errorDetail\":\""+errorDetail+"\"}";
    }
    public RestClientException() {
    }

    public RestClientException(String message) {
        super(message);
        this.message = message;
    }

    public RestClientException(String message, String errorDetail) {
        super(message);
        this.message = message;
        this.errorDetail = errorDetail;
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public Long getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(Long timestamp) {
        this.timestamp = timestamp;
    }

    @Override
    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getErrorDetail() {
        return errorDetail;
    }

    public void setErrorDetail(String errorDetail) {
        this.errorDetail = errorDetail;
    }


}
